package net.wicp.tams.common.es.client;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.elasticsearch.client.Response;

import net.wicp.tams.common.es.EsAssit;
import net.wicp.tams.common.http.HttpResult;

public abstract class EsClientAssit extends EsAssit {
	public static HttpResult packHttpResult(Response response) {
		HttpResult ret = new HttpResult();
		try {
			try {
				HttpEntity entity = response.getEntity();
				ret.setBody(IOUtils.toByteArray(entity.getContent()));
				ret.setContentLength(entity.getContentLength());
				ret.setContentType(entity.getContentType());
				ret.setContentEncoding(entity.getContentEncoding());
				ret.setStatusLine(response.getStatusLine());
			} finally {
				// response.close();
			}
		} catch (Exception ex) {
			ret.setErrMsg(ex.getMessage());
		}
		return ret;
	}
}
